package com.qysoft.dtkj.dtkj_gl.services.kjcj;

import java.math.BigDecimal;

import com.qysoft.rapid.dao.mybatis.RapidDao;
import com.qysoft.rapid.domain.Bean;
import com.qysoft.rapid.exceptions.BizException;

public class KJCJService {

	/**
	 * 添加信息到收藏
	 * @param userid
	 * @param infoid
	 * @throws Exception 
	 */
	public static void addFav(String userid,String infoid) throws Exception{
		BigDecimal isExist = (BigDecimal) RapidDao.queryOne("select count(1) from dtkj_fav where userid = ? and infoid = ?", userid,infoid);
		if (isExist.intValue()>0) {
			throw new BizException("该信息已被收藏！");
		}
		Bean bean = new Bean();
		bean.set("userid", userid);
		bean.set("infoid", infoid);
		RapidDao.save("dtkj_fav", bean);
	}
	
	/**
	 * 删除收藏
	 * @throws Exception 
	 */
	public static void delFav(String userid,String infoid) throws Exception{
		RapidDao.executeSql("delete from dtkj_fav where userid = ? and infoid = ?", userid,infoid);
	}
	
	/**
	 * 推送
	 * @param userids
	 * @param infoid
	 * @param fromuserid
	 * @throws Exception
	 */
	public static void push(String userids,String infoid,String fromuserid) throws Exception{
		String[] arrUserid = userids.split(",");
		for (String userid : arrUserid) {
			Bean bean = new Bean();
			bean.set("infoid", infoid);
			bean.set("fromuserid", fromuserid);
			bean.set("userid", userid);
			RapidDao.executeSql("delete from dtkj_push where userid =? and infoid = ?", bean.get("userid"),bean.get("infoid"));
			RapidDao.save("dtkj_push", bean);
		}
	}
	
}
